﻿set (EFFECT_FILES)
file (GLOB_RECURSE EFFECT_FILES "src/effects/*.cpp")

set (VG_FILES)
file (GLOB_RECURSE VG_FILES "src/vg/*.cpp")

set (UI_FILES)
file (GLOB_RECURSE UI_FILES "src/ui/*.cpp")

set (AUDIO_FILES)
file (GLOB_RECURSE AUDIO_FILES "src/audio/*.cpp")

set (EDITOR_FILES)
file (GLOB_RECURSE EDITOR_FILES "src/editor/*.cpp")

set (GLUCOSE_FILES)
file (GLOB_RECURSE GLUCOSE_FILES "src/color/*.cpp")

set (GLUCOSE_FILES 
	${GLUCOSE_FILES}
	"src/common.cpp" 
	"src/context.cpp" 
	"src/draw.cpp"
	"src/shape.cpp"
	"src/shader.cpp"
	"src/texture.cpp"
	"src/target.cpp"
	"src/amath.cpp"
	"src/transform.cpp"
	"src/shared.cpp"
	"src/font.cpp")


set (SEQ_FILES
	"src/effect.cpp" 
	"src/video.cpp"
	"src/seqbase/rendercxt.cpp"
	"src/seqbase/sequence.cpp"
	"src/seqbase/store.cpp")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
	file (GLOB CV_LIB_FILES "${OpenCV_LibDIR}\\*3411d.lib")
else()
	file (GLOB CV_LIB_FILES "${OpenCV_LibDIR}\\*3411.lib")
endif()

macro(ANIP_PROJ proj)
set (TMP_FILES ${GLUCOSE_FILES})
set (TMP_PROJ ${proj})
set (TMP_PUBLIC_LIBS)
set (TMP_PRIVATE_LIBS 
	"glm" "glad" "glfw" "freetype" "lcms")
set (TMP_INCLUDE_DIRS "include")
set (TMP_INCLUDE_LIB_DIRS
	"..\\glm-0.9.9.9"
	"..\\freetype-2.10.4\\include")
endmacro(ANIP_PROJ)

macro(ANIP_PROJ_ENTRANCE file)
set (TMP_FILES ${TMP_FILES} ${file})
endmacro(ANIP_PROJ_ENTRANCE)

macro(ANIP_PROJ_SOURCES file)
set (TMP_FILES ${TMP_FILES} ${file})
endmacro(ANIP_PROJ_SOURCES)

macro(ANIP_PROJ_USE_CV)
set (TMP_PRIVATE_LIBS ${TMP_PRIVATE_LIBS} ${OpenCV_LIBS})
set (TMP_INCLUDE_LIB_DIRS ${TMP_INCLUDE_LIB_DIRS} ${OpenCV_INCLUDE_DIRS})
endmacro(ANIP_PROJ_USE_CV)

macro(ANIP_PROJ_USE_AUDIO)
set (TMP_PUBLIC_LIBS ${TMP_PUBLIC_LIBS} "rtaudio")
set (TMP_FILES ${TMP_FILES} ${AUDIO_FILES})
endmacro(ANIP_PROJ_USE_AUDIO)

macro(ANIP_PROJ_USE_VG)
set (TMP_FILES ${TMP_FILES}
	${SEQ_FILES} 
	${EFFECT_FILES} 
	${VG_FILES})
endmacro(ANIP_PROJ_USE_VG)

macro(ANIP_PROJ_USE_UI)
set (TMP_FILES ${TMP_FILES}
	${UI_FILES})
endmacro(ANIP_PROJ_USE_UI)

macro(ANIP_PROJ_USE_EDITOR)
set (TMP_FILES ${TMP_FILES}
	${EDITOR_FILES})
endmacro(ANIP_PROJ_USE_EDITOR)

macro(ANIP_DONE_PROJ)
add_executable (${TMP_PROJ} ${TMP_FILES})

set_property (TARGET ${TMP_PROJ}
  PROPERTY
    # Enable C++17 standard compliance
    CXX_STANDARD 17
)

# for MSVC
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
	add_compile_options(/wd4068)
	add_compile_options(/wd4996)
endif()

target_link_libraries (${TMP_PROJ} PRIVATE ${TMP_PRIVATE_LIBS})
target_link_libraries (${TMP_PROJ} PUBLIC ${TMP_PUBLIC_LIBS})

target_include_directories (${TMP_PROJ} PUBLIC ${TMP_INCLUDE_DIRS})
target_include_directories (${TMP_PROJ} SYSTEM PUBLIC ${TMP_INCLUDE_LIB_DIRS})
endmacro(ANIP_DONE_PROJ)

ANIP_PROJ("sfxc")
ANIP_PROJ_ENTRANCE("tools/sfxc/sfxc.cpp")
ANIP_PROJ_SOURCES("tools/sfxc/interface.cpp")
ANIP_PROJ_SOURCES("tools/sfxc/sound.cpp")
ANIP_PROJ_USE_AUDIO()
ANIP_PROJ_USE_UI()
ANIP_DONE_PROJ()

ANIP_PROJ("netvis")
ANIP_PROJ_ENTRANCE("tools/netvis/netvis.cpp")
ANIP_DONE_PROJ()

ANIP_PROJ("colorpicker")
ANIP_PROJ_ENTRANCE("tools/colorpicker/colorpicker.cpp")
ANIP_PROJ_USE_UI()
ANIP_DONE_PROJ()

ANIP_PROJ("anip")
ANIP_PROJ_ENTRANCE("src/anip.cpp")
ANIP_PROJ_USE_CV()
ANIP_PROJ_USE_AUDIO()
ANIP_PROJ_USE_VG()
ANIP_PROJ_USE_UI()
ANIP_PROJ_USE_EDITOR()
ANIP_DONE_PROJ()

# Note in *nix you may have to manually change the permission for the build directory
# so that cmake can copy these files

#file (COPY "resource/ui" DESTINATION "/")
#file (COPY "resource/fonts" DESTINATION "/")
#file (COPY "resource/icc" DESTINATION "/")